package com.life.notes.config.utils;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @author lishuqian
 * @date 2020/6/15
 */
@Data
public class PageInfos<T> implements Serializable {
    private static final long serialVersionUID = -5216327794871359275L;
    private int pageNo = 1;
    private long totalCount;
    private int pageCount;
    private int pageSize = 10;
    private List<T> data;

    public PageInfos() {
    }

    public PageInfos(List<T> data) {
        this.data = data;
    }

    public void setTotalPage() {
        if (this.totalCount == 0L) {
            this.pageCount = 0;
        } else {
            this.pageCount = (int)(this.totalCount % (long)this.pageSize > 0L ? this.totalCount / (long)this.pageSize + 1L : this.totalCount / (long)this.pageSize);
        }

    }

    public static PageInfos pageChange(List<?> data, Page page) {
        if (data == null) {
            return null;
        } else {
            PageInfos pageInfos = new PageInfos();

            try {
                pageInfos.setPageNo(page.getPageNum());
                pageInfos.setPageSize(page.getPageSize());
                pageInfos.setTotalCount(page.getTotal());
                pageInfos.setPageCount(page.getPages());
                pageInfos.setData(data);
            } catch (Exception var4) {
                ;
            }

            return pageInfos;
        }
    }

    public static PageInfos pageChange(PageInfo<?> data, Page page) {
        if (data == null) {
            return null;
        } else {
            PageInfos pageInfos = new PageInfos();

            try {
                pageInfos.setPageNo(page.getPageNum());
                pageInfos.setPageSize(page.getPageSize());
                pageInfos.setTotalCount(page.getTotal());
                pageInfos.setPageCount(page.getPages());
                pageInfos.setData(data.getList());
            } catch (Exception var4) {
                ;
            }

            return pageInfos;
        }
    }
}
